package com.cqsd.ioc.util;

import java.util.Map;
import java.util.Objects;
import java.util.function.BiPredicate;

/**
 * @author caseycheng
 * @date 2023/3/20-00:28
 **/
public class MapUtil {
    public static <K, V> void removeIf(final Map<K, V> map, final BiPredicate<K, V> action) {
        Objects.requireNonNull(map);
        Objects.requireNonNull(action);
        final var removeList = map.entrySet()
                .stream()
                .filter((entry) -> !action.test(entry.getKey(), entry.getValue()))
                .map(Map.Entry::getKey)
                .toList();
        for (K k : removeList) {
            map.remove(k);
        }
    }
}
